package com.info.zhiduoduo.admin.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.info.zhiduoduo.admin.model.formbean.scheduletask.SwitchTaskFormBean;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.repository.entity.system.SystemScheduleTask;
import com.info.zhiduoduo.repository.entity.system.SystemScheduleTaskItem;
import com.info.zhiduoduo.repository.mapper.system.SystemScheduleTaskItemMapper;
import com.info.zhiduoduo.repository.mapper.system.SystemScheduleTaskMapper;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class SystemScheduleTaskService {

	@Resource
	SystemScheduleTaskMapper systemScheduleTaskMapper;
	@Resource
	SystemScheduleTaskItemMapper systemScheduleTaskItemMapper;

	public SmartResult<SystemScheduleTask> listTasks(BaseSimpleFormBean<String> formBean) {
		Page<SystemScheduleTask> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
		systemScheduleTaskMapper.listByName(formBean.getReqdata());
		return SmartResult.ofPage(page);
	}

	public SmartResult switchTask(BaseSimpleFormBean<SwitchTaskFormBean> formBean) {
		SwitchTaskFormBean reqdata = formBean.getReqdata();
		new SystemScheduleTask().setId(reqdata.getId()).setState(reqdata.getState()).updateById();
		return SmartResult.success();
	}

	public SmartResult<SystemScheduleTaskItem> listTaskItems(BaseSimpleFormBean<Integer> formBean) {
		Page<SystemScheduleTaskItem> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
		systemScheduleTaskItemMapper.listByTaskId(formBean.getReqdata());
		return SmartResult.ofPage(page);
	}
}
